﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using Kratos.Framework.Extensions.HtmlHelperExtensions;
using Kratos.Framework.Infrastructures;

namespace Kratos.Framework.Extensions
{
    public static class KratosPageExtensions
    {
        public static PageList<T> ToPageList<T>(this IQueryable<T> source, int pageIndex, int pageSize)
        {
            return new PageList<T>(source, pageIndex, pageSize);
        }

        public static PageList<T> ToPageList<T>(this IEnumerable<T> source, int pageIndex, int pageSize)
        {
            return new PageList<T>(source, pageIndex, pageSize);
        }

        public static MvcHtmlString Pager(this AjaxHelper ajax, IPage pageInfo, string action, string controller, AjaxOptions options)
        {
            var pageBuilder = new KratosPage(ajax, pageInfo, action, controller, options);
            return MvcHtmlString.Create(pageBuilder.Render());
        }

        public static MvcHtmlString Pager(this AjaxHelper ajax, IPage pageInfo, string action, string controller, AjaxOptions options, int showNumbers, int step = 5)
        {
            var pageBuilder = new KratosPage(ajax, pageInfo, action, controller, options, showNumbers, step);
            return MvcHtmlString.Create(pageBuilder.Render());
        }
    }
}
